package com.xdcplus.web.controller.alarm;

import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.web.common.pojo.dto.TreeDto;
import com.xdcplus.web.common.pojo.dto.alarm.ToolAlarmGroupDTO;
import com.xdcplus.web.common.pojo.dto.alarm.ToolAlarmGroupUpdateDTO;
import com.xdcplus.web.common.pojo.entity.alarm.ToolAlarmGroup;
import com.xdcplus.web.service.alarm.ToolAlarmGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.Validation;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 设备告警组表(ToolAlarmGroup)表服务控制层
 *
 * @author bullion.yan
 * @since 2024-06-05 16:16:14
 */
@Api(tags = "设备告警组表(ToolAlarmGroup)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("toolAlarmGroup")
public class ToolAlarmGroupController extends AbstractController {

    @Autowired
    private ToolAlarmGroupService toolAlarmGroupService;

    @ApiOperation("新增设备告警组表")
    @PostMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveToolAlarmGroup(@Valid @RequestBody ToolAlarmGroupDTO toolAlarmGroupDTO) {
        Validation.buildDefaultValidatorFactory().getValidator().validate(toolAlarmGroupDTO);
        toolAlarmGroupDTO.setCreatedUser(getAccount());
        toolAlarmGroupService.saveToolAlarmGroup(toolAlarmGroupDTO);
        return ResponseVO.success();
    }

    @ApiOperation("修改设备告警组表")
    @PutMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateToolAlarmGroup(@Valid @RequestBody ToolAlarmGroupUpdateDTO toolAlarmGroupUpdateDTO) {
        toolAlarmGroupUpdateDTO.setUpdatedUser(getAccount());
        toolAlarmGroupService.updateToolAlarmGroup(toolAlarmGroupUpdateDTO);
        return ResponseVO.success();
    }

    @ApiOperation("删除设备告警组表")
    @DeleteMapping(value = "/{toolAlarmGroupId}", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "toolAlarmGroupId", dataTypeClass = Long.class, value = "设备告警组表ID", required = true),
    })
    public ResponseVO deleteToolAlarmGroupLogical(@PathVariable("toolAlarmGroupId")
                                         @NotNull(message = "设备告警组表ID不能为空") Long toolAlarmGroupId) {
        toolAlarmGroupService.deleteToolAlarmGroupLogical(toolAlarmGroupId);
        return ResponseVO.success();
    }



    @ApiOperation("查询设备点检分类树")
    @GetMapping(value = "/findToolAlarmGroupTree", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO<List<TreeDto<ToolAlarmGroup>>> findToolAlarmGroupTree(){
        return ResponseVO.success(toolAlarmGroupService.findToolAlarmGroupTree());
    }

}
